#ifndef _NANDFLASH_H27U4G8_H
#define _NANDFLASH_H27U4G8_H


#include "main.h"

#define NAND_FLASH_DATAWITH_8   0
#define NAND_FLASH_DATAWITH_16  1

#define NAND_FLASH_DATAWITH NAND_FLASH_DATAWITH_8

#define NAND_NWAIT_STATUS() ((HAL_GPIO_ReadPin(NAND_NWAIT_GPIO_Port, NAND_NWAIT_Pin) == GPIO_PIN_RESET)?0:1)


typedef struct
{
uint32_t        TotalBlocks;
uint32_t        PhysicalPagesPerBlocks;
uint32_t        BytesPerPhysicalPage;
uint32_t        WordsPerPhysicalPage;
uint32_t        SpareBytesPerPage;
}T_NAND_BASEMSG;

typedef enum
{
    E_NANDERR_NO = 0,
    E_NANDERR_TIMEOUT,
    E_NANDERR_ERASEVERIFY,
    E_NANDERR_PARAM
}E_NAND_ERR;



uint32_t NAND_Read(
    uint16_t Block,
    uint16_t Page,
    uint16_t PageOffset,
    uint8_t *pReadBuff,
    uint32_t len );

uint32_t NAND_Write(
    uint16_t Block,
    uint16_t Page,
    uint16_t PageOffset,
    uint8_t *pWriteBuff,
    uint32_t len );

uint32_t NAND_EraseBlock( uint16_t Block );
uint32_t NAND_EraseBlockVerify( uint16_t Block );
uint32_t NAND_EraseAll( void );
uint32_t NAND_PageErasedVerify( uint16_t Block, uint16_t Page );

uint32_t NAND_SpareDataWrite(
    uint16_t Block,
    uint16_t Page,
    uint16_t PageOffset,
    uint8_t *pWriteBuff,
    uint8_t len );

uint32_t NAND_SpareDataRead(
    uint16_t Block,
    uint16_t Page,
    uint16_t PageOffset,
    uint8_t *pReadBuff,
    uint8_t len );







#endif

